package ms.unicorn.diagram.providers;

import ms.unicorn.Element;
import ms.unicorn.diagram.view.ViewEx;
import ms.unicorn.dsl.ILanguageElement;
import ms.unicorn.dsl.LanguageRegistry;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.gef.EditPart;
import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil;
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
import org.eclipse.gmf.runtime.notation.View;

public class EditPartProvider extends UnicornEditPartProvider {

	@Override
	protected IGraphicalEditPart createEditPart(View view) {
		EditPart part = null;
		EObject element = ViewUtil.resolveSemanticElement(view);
		if (element instanceof Element) {
			Element e = (Element) element;
			ILanguageElement le = LanguageRegistry.INSTANCE.getLanguageElement(e);
			if (le != null)
				part =  le.createEditPart(view);  //le.getAdvisor().createEditPart(null, view);
		}
		if (!(part instanceof IGraphicalEditPart))
			part = super.createEditPart(view);
		return (IGraphicalEditPart) part;
	}
}
